package com.monitor.app_monitor.service.quartz.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.monitor.app_monitor.config.ClickHouseConfig;
import com.monitor.app_monitor.entity.EmsInfo;
import com.monitor.app_monitor.entity.TableList;
import com.monitor.app_monitor.entity.TaskLogAnnotation;
import com.monitor.app_monitor.entity.TrsSegInfoDto;
import com.monitor.app_monitor.entity.mapper.RealTimeAlarmClickhouseMapper;
import com.monitor.app_monitor.entity.mapper.ResUnifClickhouseMapper;
import com.monitor.app_monitor.mapper.EmsInfoMapper;
import com.monitor.app_monitor.mapper.TableListMapper;
import com.monitor.app_monitor.service.quartz.utils.logUtils;
import io.micrometer.core.instrument.ImmutableTag;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @ClassName dataNbCheck.java
 * @Author ning
 * @Description TODO
 * @CreateTime 2021年12月13日 17:11:00
 */


@DisallowConcurrentExecution //作业不并发
@Component
@Slf4j
public class TrsSegInfo implements Job {

    @Resource
    private ClickHouseConfig clickHouseConfig;

    @Resource
    @Qualifier("TrsSegInfo")
    private Map<String, AtomicInteger> TrsSegInfo;

    @Autowired
    MeterRegistry registry;


    @Autowired
    TableListMapper tableListMapper;

    @Autowired
    RealTimeAlarmClickhouseMapper realTimeAlarmClickhouseMapper;

    @Autowired
    ResUnifClickhouseMapper resUnifClickhouseMapper;

    @TaskLogAnnotation
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

    /**
     * 分网管监控一干数据
     */


        List<TrsSegInfoDto> trsSegInfo = resUnifClickhouseMapper.getTrsSegInfo();

        for (TrsSegInfoDto trsSegInfoDto : trsSegInfo) {
            List<Tag> tags = new ArrayList<>();

            tags.add(new ImmutableTag("trs_type",trsSegInfoDto.getTrsType()));
            AtomicInteger filenbint = registry.gauge("trs_seg_no", tags, new AtomicInteger(trsSegInfoDto.getTrsNo()));

            if (TrsSegInfo.containsKey(trsSegInfoDto.getTrsType())) {
                TrsSegInfo.get(trsSegInfoDto.getTrsType()).set(trsSegInfoDto.getTrsNo());
            } else {
                TrsSegInfo.put(trsSegInfoDto.getTrsType(),filenbint);
            }

        }

    }
}
